package housing.task1.actor;

import housing.task1.document.Request;
import housing.task1.document.WorkPlan;

/**
 * @author Marshall
 */
public class Dispatcher extends Human {

    public Dispatcher() {
        super();
    }//Dispatcher()


    private void formBrigade() {
        final WorkPlan plan = WorkPlan.getInstance();
        for (Request r : plan.getRequests()) {
            for (Worker brigade : plan.getWorkers()) {
                if (brigade.isIddle(r.getDate()) && (brigade.getSpecialty() == r.getWork())) {
//                    brigade.assignToWork(r.getDate(),
//                            WorkScale.setWorkEndDate(r.getDate(), r.getScale()));
                    brigade.assignToWork(r);
                    updateWorkPlan(r, brigade);
                }//if(isIddle)
            }//for each(brigade)
        }//for each(request)
    }//void formBrigade()

    private void updateWorkPlan(Request r, Worker brigade) {
        WorkPlan.getInstance().update(r.getDate(), r.getSender(), r.getWork(), brigade);
    }//void updateWorkPlan()

    @Override
    public void act() {
        System.out.println("Dispatcher " + get_firstName() + " is working");
        formBrigade();
    }

    @Override
    public String toString() {
        return ("Dispather: " + this.get_firstName());
    }//void showInfo()

}//class Dispatcher
